package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.IMemberDao;
import com.itheima.dao.Member;
import com.itheima.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


@Service(interfaceClass = IMemberService.class)
@Transactional
public class MemberServiceImpl implements IMemberService {

    @Autowired
    private IMemberDao memberDao;

    /**
     * 根据手机号查找会员信息
     * @param telephone
     * @return
     */
    @Override
    public Member findByTelephone(String telephone) {

        return memberDao.findByTelephone(telephone);
    }

    /**
     * 注册会员
     * @param member
     */
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    /**
     * 根据月份查询会员数量
     * @param months
     * @return
     */
    @Override
    public List<Integer> findCountByBeforeMonth(List<String> months) {

        List<Integer> list = new ArrayList<Integer>();

        for (String month : months) {
            month = month + ".31";
            Integer count = memberDao.findCountByBeforeMonth(month);
            list.add(count);
        }

        return list;
    }

    /**
     * 根据给定日期区间查找
     * @param months
     * @return
     */
    @Override
    public List<Integer> findCountByTimeInterval(List<String> months) {
        List<Integer> list = memberDao.findCountByTimeInterval(months);
        return list;
    }
}
